package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.constant.StringConstant;
import lombok.Getter;

import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @time 2019/8/27 10:54
 * @since v1.0
 */
@Getter
public enum ProductPrintHelpEnum {
    //新建编辑显示
    PRODUCT_NAME("text_1","name","enum.productPrintHelp.attrName.product_name"),
    PRODUCT_NO("2401,serialNo","productNo","enum.productPrintHelp.attrName.product_no"),
    SPECIFICATION("2401,text_5","specification","enum.productPrintHelp.attrName.specification"),
    BARCODE("2401,text_3","barcode","enum.productPrintHelp.attrName.barcode"),
    PICTURE("2401,file_1","file_1","enum.productPrintHelp.attrName.picture"),
    PRICE("num_1","productPrice","enum.productPrintHelp.attrName.price"),
    DISCOUNT("num_4","saleDiscount","enum.productPrintHelp.attrName.discount"),
    SELLING_PRICE("num_6","saleProductPrice","enum.productPrintHelp.attrName.selling_price"),
    NUM("num_3","num","enum.productPrintHelp.attrName.num"),
    MEMO("text_3","memo","enum.productPrintHelp.attrName.memo"),
    UNIT("text_8","unit","enum.productPrintHelp.attrName.unit"),
    STOCK("num_12","stock","enum.productPrintHelp.attrName.stock"),
    SUBTOTAL("num_5","subtotal","enum.productPrintHelp.attrName.subtotal"),
    COST("num_2","productCost","enum.productPrintHelp.attrName.cost"),
    TOTAL_COST("num_7","totalCost","enum.productPrintHelp.attrName.total_cost"),
    //批次管理字段
    BATCH("text_5","batch","enum.productPrintHelp.attrName.batch"),
    PRODUCE_DATE("num_8","produceDate","enum.productPrintHelp.attrName.produce_date"),
    GUARANTEE_PERIOD("num_9","guaranteePeriod","enum.productPrintHelp.attrName.guarantee_period"),
    WAREHOUSE("text_6","warehouse","enum.productPrintHelp.attrName.warehouse"),
    //退货相关专属,对应的出入库单
    SOURCE_DOC("text_10","sourceDoc","enum.productPrintHelp.attrName.source_doc"),
    //盘点单专属
    INVENTORY("text_11","inventory","enum.productPrintHelp.attrName.inventory"),
    //bom单、生产单专属
    LOSS_RATE("num_11","attritionRate","enum.productPrintHelp.attrName.loss_rate"),
    //新建编辑隐藏，详情展示
    INSTOCK_NUM("num_17","inNum","enum.productPrintHelp.attrName.instock_num"),
    OUTSTOCK_NUM("num_13","outNum","enum.productPrintHelp.attrName.outstock_num"),
    WAIT_INSTOCK_NUM("num_14","waitInNum","enum.productPrintHelp.attrName.wait_instock_num"),
    WAIT_OUTSTOCK_NUM("num_15","waitOutNum","enum.productPrintHelp.attrName.wait_outstock_num"),
    RETURN_NUM("num_16","returnNum","enum.productPrintHelp.attrName.return_num"),
    OUT_OF_STOCK("num_18","lackNum","enum.productPrintHelp.attrName.out_of_stock"),
    CONTRACT_STATUS("text_9","outstock","enum.productPrintHelp.attrName.contract_status"),
    //
    SOURCE_SOURCE_DOC("text_71","sourceDoc","enum.productPrintHelp.attrName.source_source_doc"),
    SOURCE_PRICE("num_41","price","enum.productPrintHelp.attrName.source_price"),
    SOURCE_BATCH("text_72","batch","enum.productPrintHelp.attrName.source_batch"),
    SOURCE_PRODUCE_DATE("num_42","productDate","enum.productPrintHelp.attrName.source_produce_date"),
    SOURCE_GUARANTEE_PERIOD("num_43","guaranteePeriod","enum.productPrintHelp.attrName.source_guarantee_period"),
    SHIPMENTS_NUM("num_10","shipmentsNum","enum.productPrintHelp.attrName.shipments_num"),
    UNKONW("未知","","unknow"),
    ;

    private String newAttr;

    private String oldAttr;

    private String attrName;



    ProductPrintHelpEnum(String newAttr, String oldAttr, String attrName) {
        this.newAttr = newAttr;
        this.oldAttr = oldAttr;
        this.attrName = attrName;
    }

    public static String getOldAttrByNewAttr(String newAttr){
        for (ProductPrintHelpEnum productPrintHelpEnum : ProductPrintHelpEnum.values()){
            if (Objects.equals(newAttr,productPrintHelpEnum.getNewAttr())){
                return productPrintHelpEnum.getOldAttr();
            }
        }
        return null;
    }

    public static ProductPrintHelpEnum getByNewAttrContact(String attr) {
        for (ProductPrintHelpEnum productPrintHelpEnum : ProductPrintHelpEnum.values()){
            String newAttr = XbbRefTypeEnum.PRODUCT.getCode() + StringConstant.COMMA + attr;
            if (Objects.equals(productPrintHelpEnum.getNewAttr(), newAttr)){
                return productPrintHelpEnum;
            }
        }
        return null;
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }
}
